package com.cc.service.impl;

import com.cc.dao.employeeDao;
import com.cc.dao.impl.employeeImpl;
import com.cc.entity.PageRest;
import com.cc.entity.employee;
import com.cc.service.employeeService;

import java.util.List;

public class employeeServiceImpl implements employeeService {
    private employeeDao employeeDao = new employeeImpl();


    @Override
    public List<employee> getAll(String empName) {
        return employeeDao.getAll(empName);
    }

    @Override
    public boolean add(employee eply) {
        return employeeDao.add(eply)==1;
    }
    @Override
    public employee getById(int id) {
        return employeeDao.getEdit(id);
    }

    @Override
    public boolean update(employee e) {
        return employeeDao.UpdateEmq(e) >0;
    }

    @Override
    public boolean  delete(int e) {
        return employeeDao.delete(e) >0;
    }

    @Override
    public PageRest<employee> getPage(int pageNum, int pageSize, String empName) {
        PageRest<employee> pageRest=new PageRest<>();
        pageRest.setPageNum(pageNum);
        pageRest.setPageSize(pageSize);
        //获取总记录数
        int totalCount= employeeDao.getTotalCount(empName);
        pageRest.setTotalCount(totalCount);
        //获取当前页数据
        List<employee> data= employeeDao.getPage(pageNum,pageSize,empName);
        pageRest.setData(data);
        return pageRest;
    }
}
